<template>
  <div>
    <el-card shadow="never" class="aui-card--fill">
      <el-collapse-transition>
        <el-form v-if="searchShow" :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
          <el-form-item>
            <el-input v-model="dataForm.dictName" :placeholder="$t('dict.dictName')" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="dataForm.dictType" :placeholder="$t('dict.dictType')" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-button @click="getDataList()" type="primary">{{ $t('query') }}</el-button>
            <el-button @click="searchReset()">{{ $t('reset') }}</el-button>
          </el-form-item>
        </el-form>
      </el-collapse-transition>
      <vxe-toolbar>
        <template v-slot:buttons>
          <el-button v-if="$hasPermission('sys:export-data:export')" type="primary" @click="exportHandle()">
            {{$t('dataExport.exportButtonTitle')}}
          </el-button>
        </template>
        <template v-slot:tools>
          <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
        </template>
      </vxe-toolbar>
      <vxe-table :loading="dataListLoading" :data="dataList" ref="xTable" auto-resize class="vxe-table-element"
        @select-change="dataListSelectionChangeHandleVex" @select-all="dataListSelectionAllChangeHandleVex">
        <vxe-table-column type="checkbox" width="50"></vxe-table-column>
        <vxe-table-column field="dictName" title="dict.dictName"></vxe-table-column>
        <vxe-table-column field="dictType" title="dict.dictType" align="left">
          <template slot-scope="scope">
            {{ scope.row.dictType }}
          </template>
        </vxe-table-column>
        <vxe-table-column field="isSys" title="dict.isSys" width="80" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.isSys == 0" size="small" type="info">{{ $t('dict.isSys0') }}</el-tag>
            <el-tag v-else size="small" type="success">{{ $t('dict.isSys1') }}</el-tag>
          </template>
        </vxe-table-column>
        <vxe-table-column field="status" title="dict.state" width="80" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status == 0" size="small" type="danger">{{ $t('dict.status0') }}</el-tag>
            <el-tag v-else size="small" type="success">{{ $t('dict.status1') }}</el-tag>
          </template>
        </vxe-table-column>
      </vxe-table>
      <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
        layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import qs from 'qs'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/sys/exportData/dict/page',
        getDataListIsPage: true,
        exportURL: '/sys/exportData/dict/export'
      }
    }
  },
  methods: {
    // 导出
    exportHandle () {
      if (this.dataListSelections.length <= 0) {
        return this.$message({
          message: this.$t('dataExport.messageNo'),
          type: 'warning',
          duration: 500
        })
      }
      this.$prompt(this.$t('title'), this.$t('prompt.title'), {
        confirmButtonText: this.$t('confirm'),
        cancelButtonText: this.$t('cancel'),
        inputPattern: /^\d+(\.\d+)?$/,
        inputErrorMessage: this.$t('dataExport.inputErrorMessage')
      }).then(({ value }) => {
        var params = qs.stringify({
          'token': this.$cookies.get('token'),
          'version': value,
          'ids': this.dataListSelections.map(item => item['id']).join(',')
        })
        window.location.href = `${window.SITE_CONFIG['apiURL']}${this.mixinViewModuleOptions.exportURL}?${params}`
      }).catch(() => {

      })
    }
  },
  components: {}
}
</script>
